﻿Imports DTO
Imports System.Data.OleDb
Public Class ThamSoDAO
    'lấy bảng tham số
    Public Function LayBangThamSo() As ThamSoDTO
        Dim sql As String = "Select * From THAMSO"
        Dim con As OleDbConnection = DataProvider.ConnectDB()
        Dim cmd As New OleDbCommand(sql, con)
        Dim reader As OleDbDataReader = cmd.ExecuteReader()
        Dim tsDTO As New ThamSoDTO()
        While (reader.Read())
            tsDTO.SoTienGoiToiThieu = reader.GetDouble(0)
            tsDTO.MaLoaiTietKiemDuocGoiTien = reader.GetInt32(1)
            tsDTO.SoNgayRutTienSauKhiMoSo = reader.GetInt32(2)
        End While
        con.Close()
        Return tsDTO
    End Function

    'Kiểm tra số tiển gởi tối thiểu
    Public Function KiemTraSoTienGoi(ByVal sotiengoi As Double, ByVal sotiengoitoithieu As Double) As Boolean
        If sotiengoi < sotiengoitoithieu Then
            Return False
        Else
            Return True
        End If
    End Function
    Public Shared Function KiemTraNgayRut(ByVal ngayrut As Date, ByVal ngaymoso As Date) As Boolean
        Dim tsDTO As New ThamSoDTO()
        Dim tsDAO As New ThamSoDAO()
        tsDTO = tsDAO.LayBangThamSo()
        Dim ngayruttoithieu As Integer = tsDTO.SoNgayRutTienSauKhiMoSo
        If ngayrut.DayOfYear - ngaymoso.DayOfYear > ngayruttoithieu Then
            Return True
        Else
            Return False
        End If

    End Function

    Public Function ImportExcel(ByVal str As String) As DataTable
        Dim dt As New DataTable()
        Dim cnn As New OleDbConnection()
        cnn = DataProvider.KetNoiExcel(str)
        Dim strSQL = "SELECT * FROM [Sheet1$]"
        Dim comand As New OleDbCommand(strSQL, cnn)
        Dim Adapter As New OleDbDataAdapter(comand)
        Adapter.Fill(dt)
        Return dt
    End Function

End Class
